/*
 * Copyright (c) 2007 Compl Yue Still, All Rights Reserved.
 */

package hbi.wire.as3.host
{
	import flash.utils.IDataInput;

	public class UntypedArray implements DataTag
	{
		
		public function get tagValue():*
		{
			return values.tagValues;
		}
		
		public function reset():void
		{
			values = null;
		}
		
		private var values:DataTagList = null;
		
		public function processIncomingData(input:IDataInput):Boolean
		{
			if(values == null) // length not read yet
			{
				if(input.bytesAvailable < 4) // length not yet available
					return false;
				var length:int = input.readInt();
				if(length < 0) throw new Error("Too large array!");
				values = new DataTagList(length);
			}
			
			if(input.bytesAvailable < 1) return false;
			
			if(values.processIncomingData(input))
				return true;
			
			return false;
		}
		
	}
}
